package com.study.talk.module.entity.resp;

import com.alibaba.fastjson2.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.study.talk.common.util.GsonUtil;
import com.study.talk.module.entity.Moment;
import com.study.talk.module.entity.MomentComment;
import com.study.talk.module.entity.MomentLike;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.lang.reflect.Array;
import java.time.LocalDateTime;
import java.util.ArrayList;

import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class MomentResponse {

    private Integer id;

    @ApiModelProperty("发布者id")
    private Integer userId;

    @ApiModelProperty("发布者图片")
    private String avatar;

    @ApiModelProperty("发布者名称")
    private String  userName;

    @ApiModelProperty("动态图片")
    private ArrayList<String> photos;

    @ApiModelProperty("动态内容")
    private String content;

    @ApiModelProperty("点赞数")
    private Integer likeCount;

    @ApiModelProperty("我的点赞状态")
    private Integer myLikeState;

    @ApiModelProperty("创建时间")
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @JSONField(format="yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    @ApiModelProperty("点赞好友列表")
    private ArrayList<MomentLike> momentLikes;

    @ApiModelProperty("评论好友列表")
    private ArrayList<MomentComment> momentComments;


    public MomentResponse(Moment moment,Integer myLikeState, ArrayList<MomentLike> momentLikes, ArrayList<MomentComment> momentComments) {
        this.id = moment.getId();
        this.userId = moment.getUserId();
        this.avatar = moment.getAvatar();
        this.userName = moment.getUserName();
        this.photos = GsonUtil.instance.fromJson(moment.getPhotos(),new TypeToken<ArrayList<String>>(){}.getType());
        this.content = moment.getContent();
        this.likeCount = moment.getLikeCount();
        this.createTime = moment.getCreateTime();
        this.myLikeState = myLikeState;
        this.momentLikes = momentLikes;
        this.momentComments = momentComments;
    }
}
